Malaysia Covid19 Cases Updates

Prepared By: Zahiruddin Zahidanishah

In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
import dataframe_image as dfi
import adjustText as aT
from jupyterthemes import jtplot
#import requests
import cufflinks as cf
#from bs4 import BeautifulSoup as bs
jtplot.style(theme='monokai', context='notebook', ticks=True, grid=False) 
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot 
init_notebook_mode(connected=True)
cf.go_offline()

from IPython.display import display_html
def display_side_by_side(*args):
    html_str=''
    for df in args:
        html_str+=df.to_html()
    display_html(html_str.replace('table','table style="display:inline"'),raw=True)
In [2]:
#Covid19 Malaysia States Dataset from MOH, Malaysia Github accounts 
df_states_cases = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_state.csv')
df_states_deaths = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_state.csv')
df_states_hosp = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/hospital.csv')
df_states_icu = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/icu.csv')
df_states_pkrc = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/pkrc.csv')
df_states_test = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_state.csv')
df_states_vaksin = pd.read_csv('https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_state.csv')
df_states_pop = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/static/population.csv')
In [3]:
df_hosp_daily = df_states_hosp.groupby('date').sum().reset_index()
df_hosp_daily['admitted_covid_cum'] = df_hosp_daily['admitted_covid'].cumsum()
df_hosp_daily['discharged_covid_cum'] = df_hosp_daily['discharged_covid'].cumsum()
df_icu_daily = df_states_icu.groupby('date').sum().reset_index()
df_icu_daily['icu_covid_cum'] = df_icu_daily['icu_covid'].cumsum()
df_pkrc_daily = df_states_pkrc.groupby('date').sum().reset_index()
df_pkrc_daily['admitted_covid_cum'] = df_pkrc_daily['admitted_covid'].cumsum()
df_pkrc_daily['discharged_covid_cum'] = df_pkrc_daily['discharged_covid'].cumsum()
In [4]:
#Selecting the required columns
df_states_cases = df_states_cases[['date','state','cases_new','cases_recovered','cases_pvax','cases_fvax','cases_boost']]
df_date_start = df_states_cases.head(1)
df_date_end = df_states_cases.tail(1)
df_states_deaths = df_states_deaths[['date','state','deaths_new','deaths_bid_dod','deaths_pvax','deaths_fvax','deaths_boost']]
df_states_hosp = df_states_hosp[['date','state','admitted_covid','discharged_covid']]
df_states_vaksin = df_states_vaksin[['date','state','daily_partial','daily_full','daily_booster','daily']]
df_states_pop = df_states_pop[['state','pop']]
In [5]:
#Grouping and summation the detasets based on states columns
df_cases = df_states_cases.groupby('state').sum()
df_deaths = df_states_deaths.groupby('state').sum()
df_hosp = df_states_hosp.groupby('state').sum()
df_vaksin = df_states_vaksin.groupby('state').sum()
In [6]:
#Dataset for overall Malaysia Covid19
df_mas_cases = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv')
df_mas_deaths = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_malaysia.csv')
df_mas_test = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_malaysia.csv')
df_mas_vaksin = pd.read_csv('https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_malaysia.csv')
df_mas_pop = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/static/population.csv')
df_mas_aefi = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/vaccination/aefi.csv')
In [7]:
df_mas_vaksin['Total Pfizer'] = df_mas_vaksin['pfizer1'] + df_mas_vaksin['pfizer2']
df_mas_vaksin['Total Sinovac'] = df_mas_vaksin['sinovac1'] + df_mas_vaksin['sinovac2']
df_mas_vaksin['Total AstraZ'] = df_mas_vaksin['astra1'] + df_mas_vaksin['astra2']
df_mas_vaksin['Cum. Daily'] = df_mas_vaksin['daily_full'].cumsum()
df_mas_vaksin['Population'] = df_states_pop.at[df_states_pop.index[0],'pop']
df_mas_vaksin['Vax. (%)'] = (df_mas_vaksin['Cum. Daily']/df_mas_vaksin['Population'])*100
In [8]:
df_mas_cases = df_mas_cases[['date','cases_new','cases_recovered','cases_pvax','cases_fvax','cases_active','cases_boost']]
df_mas_deaths = df_mas_deaths[['date','deaths_new','deaths_bid_dod','deaths_pvax','deaths_fvax','deaths_boost']]
df_mas_vaksin = df_mas_vaksin[['date', 'daily_partial', 'daily_full', 'daily_booster', 'daily', 'Total Pfizer',
                               'Total Sinovac', 'Total AstraZ', 'cansino', 'Cum. Daily', 'Vax. (%)']]
In [9]:
df_mas = pd.merge(df_mas_cases, df_mas_deaths, on='date')
In [10]:
df_mas = pd.merge(df_mas, df_mas_vaksin, on='date')
In [11]:
#Merging the datasets into one datasets
df_states = pd.merge(df_cases,df_deaths,on='state')
In [12]:
df_states = pd.merge(df_states,df_hosp,on='state')
In [13]:
df_states = pd.merge(df_states,df_vaksin,on='state')
In [14]:
df_states = pd.merge(df_states,df_states_pop,on='state')
In [15]:
#Creating main tables for presentation
df_states_table = df_states
df_states_table['deaths_vax_total'] = df_states_table['deaths_pvax'] + df_states_table['deaths_fvax'] + df_states_table['deaths_boost']
df_states_table['cases_vax_total'] = df_states_table['cases_pvax'] + df_states_table['cases_fvax']+ df_states_table['cases_boost']

df_states_table = df_states_table[['state','cases_new','cases_recovered','cases_vax_total','deaths_new',
                                  'deaths_bid_dod','deaths_vax_total','daily_partial','daily_full','daily',
                                   'daily_booster','pop']]

df_states_table.loc['Total'] = df_states_table.sum(numeric_only=True, axis=0)
df_states_table['state'] = df_states_table['state'].replace(np.nan, 'Malaysia')

df_states_table['Cases (%)'] = df_states_table['cases_new']/df_states_table['pop']*100
df_states_table['Cases Recovered (%)'] = df_states_table['cases_recovered']/df_states_table['cases_new']*100
df_states_table['Cases Vax. (%)'] = df_states_table['cases_vax_total']/df_states_table['cases_new']*100
df_states_table['Deaths (%)'] = df_states_table['deaths_new']/df_states_table['cases_new']*100
df_states_table['Deaths Vax. (%)'] = df_states_table['deaths_vax_total']/df_states_table['deaths_new']*100
df_states_table['Deaths BID (%)'] = df_states_table['deaths_bid_dod']/df_states_table['deaths_new']*100
df_states_table['Vax. 3D (%)'] = df_states_table['daily_booster']/df_states_table['pop']*100
df_states_table['Vax. 2D (%)'] = df_states_table['daily_full']/df_states_table['pop']*100
df_states_table['Vax. 1D (%)'] = df_states_table['daily_partial']/df_states_table['pop']*100

df_states_table.rename(columns={'state':'States','cases_new':'Cases Positive','cases_recovered':'Cases Recovered',
                               'cases_vax_total':'Cases Vax.','deaths_new':'Death Cases',
                               'deaths_bid_dod':'Death BID','deaths_vax_total':'Deaths Vax.',
                               },inplace=True)#'daily':'Total Vaccinated','pop':'Population'
In [16]:
print('Report Start Date :', df_date_start.at[df_date_start.index[0],'date'])
print('Report End Date   :', df_date_end.at[df_date_end.index[0],'date'])
Report Start Date : 2020-01-25
Report End Date   : 2022-04-20
In [17]:
df_mas_cases['total_vax'] = df_mas_cases['cases_pvax'] + df_mas_cases['cases_fvax'] + df_mas_cases['cases_boost']
df_mas_cases['cum_new'] = df_mas_cases['cases_new'].cumsum()
df_mas_cases['cum_recovered'] = df_mas_cases['cases_recovered'].cumsum()
df_mas_cases['cum_vax'] = df_mas_cases['total_vax'].cumsum()
df_mas_cases['active_cum'] = df_mas_cases['cases_active'].cumsum()

df_mas_deaths['total_vax'] = df_mas_deaths['deaths_pvax'] + df_mas_deaths['deaths_fvax'] + df_mas_deaths['deaths_boost']
df_mas_deaths['cum_deaths'] = df_mas_deaths['deaths_new'].cumsum()
df_mas_deaths['cum_vax'] = df_mas_deaths['total_vax'].cumsum()
In [18]:
df_mas_monthly = df_mas_cases.append(df_mas_deaths)

def getYearMonth(s):
  return s.split("-")[1]+"-"+s.split("-")[0]
df_mas_monthly['YearMonth']= df_mas_monthly['date'].apply(lambda x: getYearMonth(x))

df_mas_monthly = df_mas_monthly.groupby('YearMonth').sum()
df_mas_monthly = df_mas_monthly.reset_index()
df_mas_monthly['vax_total_cases'] = df_mas_monthly['cases_fvax']+df_mas_monthly['cases_pvax']
df_mas_monthly['vax_total_deaths'] = df_mas_monthly['deaths_fvax']+df_mas_monthly['deaths_pvax']+df_mas_monthly['deaths_boost']
In [19]:
df_mas_yearly = df_mas_cases.append(df_mas_deaths)

def getYear(s):
  return s.split("-")[0]

def getMonth(s):
  return s.split("-")[1]

df_mas_yearly['Year']= df_mas_yearly['date'].apply(lambda x: getYear(x))
df_mas_yearly['Month']= df_mas_yearly['date'].apply(lambda x: getMonth(x))

df_mas_yearly = df_mas_yearly.groupby('Year').sum().reset_index()
df_mas_yearly['vax_total_cases'] = df_mas_yearly['cases_fvax'] + df_mas_yearly['cases_pvax'] + df_mas_yearly['cases_boost']
df_mas_yearly['vax_total_deaths'] = df_mas_yearly['deaths_fvax'] + df_mas_yearly['deaths_pvax'] + df_mas_yearly['deaths_boost']
In [20]:
fig = make_subplots(rows=1, cols=2, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>Yearly Total Covid19 Cases & Recovered</b>',
                                   '<b>Monthly Total Covid19 Cases & Recovered</b>'))
#Graph 1
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['cases_new'],
                        name='Cases Positive',marker_color='red'),row=1, col=1)
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['cases_recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=1)
#Graph 2
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['cases_new'],
                        name='Cases Positive',marker_color='red'),row=1, col=2)
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['cases_recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=2)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False,
                 title_text='Malaysia Covid19 Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [21]:
fig = make_subplots(rows=1, cols=2, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>Yearly Total Covid19 Death Cases</b>',
                                   '<b>Monthly Total Covid19 Death Cases</b>'))
#Graph 1
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['deaths_new'],
                        name='Death Cases',marker_color='red'),row=1, col=1)
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['vax_total_deaths'],
                        name='Death Vax Cases',marker_color='blue'),row=1, col=1)

#Graph 2
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['deaths_new'],
                        name='Death Cases',marker_color='red'),row=1, col=2)
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['vax_total_deaths'],
                        name='Death Vax Cases',marker_color='blue'),row=1, col=2)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False,
                 title_text='Malaysia Covid19 Deaths Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [22]:
df_2020 = df_mas_cases.query("date >= '2020-01-01' \
                            and date <= '2020-12-31'")
df_2021 = df_mas_cases.query("date >= '2021-01-01' \
                            and date <= '2021-12-31'")
df_2022 = df_mas_cases.query("date >= '2022-01-01' \
                            and date <= '2022-12-31'")
In [23]:
df_2020['cum_2020'] = df_2020['cases_new'].cumsum()
df_2021['cum_2021'] = df_2021['cases_new'].cumsum()
df_2022['cum_2022'] = df_2022['cases_new'].cumsum()
In [24]:
death_2020 = df_mas_deaths.query("date >= '2020-01-01' \
                            and date <= '2020-12-31'")
death_2021 = df_mas_deaths.query("date >= '2021-01-01' \
                            and date <= '2021-12-31'")
death_2022 = df_mas_deaths.query("date >= '2022-01-01' \
                            and date <= '2022-12-31'")
In [25]:
death_2020['cum_2020'] = death_2020['deaths_new'].cumsum()
death_2021['cum_2021'] = death_2021['deaths_new'].cumsum()
death_2022['cum_2022'] = death_2022['deaths_new'].cumsum()
In [26]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))

fig.add_trace(go.Scatter(x = df_2020['date'], y = df_2020['cases_new'], name = 'Daily Cases',
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_2020['date'], y = df_2020['cum_2020'], name = 'Cumulative Cases',
               line = dict(color='red', width=1.5)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_2020['date'], y = df_2020['cases_active'], name = 'Active Cases',
               line = dict(color='green', width=1.5)), secondary_y=True, row=1, col=1)

fig.add_trace(go.Scatter(x = df_2021['date'], y = df_2021['cases_new'], name = 'Cases Daily',
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=2)
fig.add_trace(go.Scatter(x = df_2021['date'], y = df_2021['cum_2021'], name = 'Cases',
               line = dict(color='red', width=1.5)), secondary_y=True, row=1, col=2)
fig.add_trace(go.Scatter(x = df_2021['date'], y = df_2021['cases_active'], name = 'Active Cases',
               line = dict(color='green', width=1.5)), secondary_y=True, row=1, col=2)

fig.add_trace(go.Scatter(x = df_2022['date'], y = df_2022['cases_new'], name = 'Daily Cases',
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=3)
fig.add_trace(go.Scatter(x = df_2022['date'], y = df_2022['cum_2022'], name = 'Cumulative Cases',
               line = dict(color='red', width=1.5)), secondary_y=True, row=1, col=3)
fig.add_trace(go.Scatter(x = df_2022['date'], y = df_2022['cases_active'], name = 'Active Cases',
               line = dict(color='green', width=1.5)), secondary_y=True, row=1, col=3)

fig.update_layout(title_text='Malaysia Covid19 Cases By Year', title_x=0.5, showlegend=False,
                 height=350)
fig.update_xaxes(title_text='')
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [27]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))

fig.add_trace(go.Scatter(x = death_2020['date'], y = death_2020['deaths_new'], name = 'Daily Death Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = death_2020['date'], y = death_2020['cum_2020'], name = 'Cumulative Death Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=1)

fig.add_trace(go.Scatter(x = death_2021['date'], y = death_2021['deaths_new'], name = 'Daily Death Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=2)
fig.add_trace(go.Scatter(x = death_2021['date'], y = death_2021['cum_2021'], name = 'Cumulative Death Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=2)

fig.add_trace(go.Scatter(x = death_2022['date'], y = death_2022['deaths_new'], name = 'Daily Death Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=3)
fig.add_trace(go.Scatter(x = death_2022['date'], y = death_2022['cum_2022'], name = 'Cumulative Death Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=3)


fig.update_layout(title_text='Malaysia Covid19 Death Cases By Year', title_x=0.5, showlegend=False,
                 height=350)
fig.update_xaxes(title_text='')
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [28]:
df_mas_yearly_table = df_mas_yearly[['Year','cases_new','vax_total_cases','cases_recovered',
                                     'deaths_new','vax_total_deaths']]

df_mas_yearly_table.rename(columns={'cases_new':'Cases Positive',
                                    'cases_recovered':'Cases Recovered',
                                    'vax_total_cases':'Cases Vax.',
                                    'deaths_new':'Death Cases',
                                    'vax_total_deaths':'Deaths Vax.'},inplace=True)

df_mas_yearly_table.loc['Total'] = df_mas_yearly_table.sum(numeric_only=True, axis=0)
df_mas_yearly_table['Overall Cases (%)'] = (df_mas_yearly_table['Cases Positive']/df_mas_yearly_table['Cases Positive'].sum())*200
df_mas_yearly_table['Cases Vax. (%)'] = (df_mas_yearly_table['Cases Vax.']/df_mas_yearly_table['Cases Positive'])*100
df_mas_yearly_table['Recovered (%)'] = (df_mas_yearly_table['Cases Recovered']/df_mas_yearly_table['Cases Positive'])*100
df_mas_yearly_table['Death (%)'] = (df_mas_yearly_table['Death Cases']/df_mas_yearly_table['Cases Positive'])*100
df_mas_yearly_table['Deaths Vax. (%)'] = (df_mas_yearly_table['Deaths Vax.']/df_mas_yearly_table['Death Cases'])*100
df_mas_yearly_table['Year'] = df_mas_yearly_table['Year'].replace(np.nan, 'Total')

df_mas_yearly_table = df_mas_yearly_table[['Year','Cases Positive','Overall Cases (%)',
                                           'Cases Vax.','Cases Vax. (%)',
                                           'Cases Recovered','Recovered (%)',
                                           'Death Cases','Death (%)',
                                           'Deaths Vax.','Deaths Vax. (%)']]

df_mas_yearly_table.style.set_caption("Malaysia Covid19 Cases Yearly").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '20px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}',
     'Death Cases':'{:,.0f}','Deaths Vax.':'{:,.0f}','Recovered (%)':'{:,.1f}',
     'Death (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Deaths Vax. (%)':'{:,.1f}',
     'Overall Cases (%)':'{:,.1f}'
    }).apply(lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[28]:
Malaysia Covid19 Cases Yearly
Year Cases Positive Overall Cases (%) Cases Vax. Cases Vax. (%) Cases Recovered Recovered (%) Death Cases Death (%) Deaths Vax. Deaths Vax. (%)
2020 113,010 2.6 0 0.0 88,940 78.7 471 0.4 0 0.0
2021 2,645,076 60.0 1,067,163 40.3 2,596,438 98.2 31,016 1.2 10,825 34.9
2022 1,651,116 37.4 1,385,454 83.9 1,597,635 96.8 3,978 0.2 2,608 65.6
Total 4,409,202 100.0 2,452,617 55.6 4,283,013 97.1 35,465 0.8 13,433 37.9
In [29]:
df_q_cases = df_mas_cases
df_q_deaths = df_mas_deaths

df_q_cases = df_q_cases[['date','cases_new','total_vax','cases_recovered']]
df_q_cases.rename(columns={'cases_new':'Cases Positive','cases_recovered':'Cases Recovered',
                             'total_vax':'Cases Vax.'},inplace=True)

df_q_deaths = df_q_deaths[['date','deaths_new','total_vax']]
df_q_deaths.rename(columns={'deaths_new':'Death Cases',
                            'total_vax':'Deaths Vax.'},inplace=True)
In [30]:
q1_cases_2020 = df_q_cases.query("date >= '2020-01-01' \
                            and date <= '2020-03-31'")
q2_cases_2020 = df_q_cases.query("date >= '2020-04-01' \
                            and date <= '2020-06-30'")
q3_cases_2020 = df_q_cases.query("date >= '2020-07-01' \
                            and date <= '2020-09-30'")
q4_cases_2020 = df_q_cases.query("date >= '2020-10-01' \
                            and date <= '2020-12-31'")

q1_deaths_2020 = df_q_deaths.query("date >= '2020-01-01' \
                            and date <= '2020-03-31'")
q2_deaths_2020 = df_q_deaths.query("date >= '2020-04-01' \
                            and date <= '2020-06-30'")
q3_deaths_2020 = df_q_deaths.query("date >= '2020-07-01' \
                            and date <= '2020-09-30'")
q4_deaths_2020 = df_q_deaths.query("date >= '2020-10-01' \
                            and date <= '2020-12-31'")

def getYear(s):
  return s.split("-")[0]

q1_cases_2020['Year']= q1_cases_2020['date'].apply(lambda x: getYear(x))
q1_cases_2020 = q1_cases_2020.groupby('Year').sum().reset_index()
q1_cases_2020['Year'] = q1_cases_2020['Year'].replace('2020', 'Q1')

q2_cases_2020['Year']= q2_cases_2020['date'].apply(lambda x: getYear(x))
q2_cases_2020 = q2_cases_2020.groupby('Year').sum().reset_index()
q2_cases_2020['Year'] = q2_cases_2020['Year'].replace('2020', 'Q2')

q3_cases_2020['Year']= q3_cases_2020['date'].apply(lambda x: getYear(x))
q3_cases_2020 = q3_cases_2020.groupby('Year').sum().reset_index()
q3_cases_2020['Year'] = q3_cases_2020['Year'].replace('2020', 'Q3')

q4_cases_2020['Year']= q4_cases_2020['date'].apply(lambda x: getYear(x))
q4_cases_2020 = q4_cases_2020.groupby('Year').sum().reset_index()
q4_cases_2020['Year'] = q4_cases_2020['Year'].replace('2020', 'Q4')

q_cases_2020 = q1_cases_2020.append([q2_cases_2020,q3_cases_2020,q4_cases_2020])

q1_deaths_2020['Year']= q1_deaths_2020['date'].apply(lambda x: getYear(x))
q1_deaths_2020 = q1_deaths_2020.groupby('Year').sum().reset_index()
q1_deaths_2020['Year'] = q1_deaths_2020['Year'].replace('2020', 'Q1')

q2_deaths_2020['Year']= q2_deaths_2020['date'].apply(lambda x: getYear(x))
q2_deaths_2020 = q2_deaths_2020.groupby('Year').sum().reset_index()
q2_deaths_2020['Year'] = q2_deaths_2020['Year'].replace('2020', 'Q2')

q3_deaths_2020['Year']= q3_deaths_2020['date'].apply(lambda x: getYear(x))
q3_deaths_2020 = q3_deaths_2020.groupby('Year').sum().reset_index()
q3_deaths_2020['Year'] = q3_deaths_2020['Year'].replace('2020', 'Q3')

q4_deaths_2020['Year']= q4_deaths_2020['date'].apply(lambda x: getYear(x))
q4_deaths_2020 = q4_deaths_2020.groupby('Year').sum().reset_index()
q4_deaths_2020['Year'] = q4_deaths_2020['Year'].replace('2020', 'Q4')

q_deaths_2020 = q1_deaths_2020.append([q2_deaths_2020,q3_deaths_2020,q4_deaths_2020])

q_graph_2020 = pd.merge(q_cases_2020,q_deaths_2020,on='Year')
q_table_2020 = pd.merge(q_cases_2020,q_deaths_2020,on='Year')

q_table_2020.loc['Total'] = q_table_2020.sum(numeric_only=True, axis=0)
q_table_2020['Overall Cases (%)'] = (q_table_2020['Cases Positive']/q_table_2020['Cases Positive'].sum())*200
q_table_2020['Cases Vax. (%)'] = (q_table_2020['Cases Vax.']/q_table_2020['Cases Positive'])*100
q_table_2020['Recovered (%)'] = (q_table_2020['Cases Recovered']/q_table_2020['Cases Positive'])*100
q_table_2020['Death (%)'] = (q_table_2020['Death Cases']/q_table_2020['Cases Positive'])*100
q_table_2020['Deaths Vax. (%)'] = (q_table_2020['Deaths Vax.']/q_table_2020['Death Cases'])*100
q_table_2020['Year'] = q_table_2020['Year'].replace(np.nan, 'Total')

q_table_2020 = q_table_2020[['Year','Cases Positive','Overall Cases (%)',
                                           'Cases Vax.','Cases Vax. (%)',
                                           'Cases Recovered','Recovered (%)',
                                           'Death Cases','Death (%)',
                                           'Deaths Vax.','Deaths Vax. (%)']]

q_table_2020.style.set_caption("Malaysia Covid19 Quarterly Report Year 2020").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '20px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}',
     'Death Cases':'{:,.0f}','Deaths Vax.':'{:,.0f}','Recovered (%)':'{:,.1f}',
     'Death (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Deaths Vax. (%)':'{:,.1f}',
     'Overall Cases (%)':'{:,.1f}'
    }).apply(lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[30]:
Malaysia Covid19 Quarterly Report Year 2020
Year Cases Positive Overall Cases (%) Cases Vax. Cases Vax. (%) Cases Recovered Recovered (%) Death Cases Death (%) Deaths Vax. Deaths Vax. (%)
Q1 2,766 2.4 0 0.0 536 19.4 48 1.7 0 0.0
Q2 5,873 5.2 0 0.0 7,817 133.1 73 1.2 0 0.0
Q3 2,585 2.3 0 0.0 1,613 62.4 15 0.6 0 0.0
Q4 101,786 90.1 0 0.0 78,974 77.6 335 0.3 0 0.0
Total 113,010 100.0 0 0.0 88,940 78.7 471 0.4 0 0.0
In [31]:
q1_cases_2021 = df_q_cases.query("date >= '2021-01-01' \
                            and date <= '2021-03-31'")
q2_cases_2021 = df_q_cases.query("date >= '2021-04-01' \
                            and date <= '2021-06-30'")
q3_cases_2021 = df_q_cases.query("date >= '2021-07-01' \
                            and date <= '2021-09-30'")
q4_cases_2021 = df_q_cases.query("date >= '2021-10-01' \
                            and date <= '2021-12-31'")

q1_deaths_2021 = df_q_deaths.query("date >= '2021-01-01' \
                            and date <= '2021-03-31'")
q2_deaths_2021 = df_q_deaths.query("date >= '2021-04-01' \
                            and date <= '2021-06-30'")
q3_deaths_2021 = df_q_deaths.query("date >= '2021-07-01' \
                            and date <= '2021-09-30'")
q4_deaths_2021 = df_q_deaths.query("date >= '2021-10-01' \
                            and date <= '2021-12-31'")

def getYear(s):
  return s.split("-")[0]

q1_cases_2021['Year']= q1_cases_2021['date'].apply(lambda x: getYear(x))
q1_cases_2021 = q1_cases_2021.groupby('Year').sum().reset_index()
q1_cases_2021['Year'] = q1_cases_2021['Year'].replace('2021', 'Q1')

q2_cases_2021['Year']= q2_cases_2021['date'].apply(lambda x: getYear(x))
q2_cases_2021 = q2_cases_2021.groupby('Year').sum().reset_index()
q2_cases_2021['Year'] = q2_cases_2021['Year'].replace('2021', 'Q2')

q3_cases_2021['Year']= q3_cases_2021['date'].apply(lambda x: getYear(x))
q3_cases_2021 = q3_cases_2021.groupby('Year').sum().reset_index()
q3_cases_2021['Year'] = q3_cases_2021['Year'].replace('2021', 'Q3')

q4_cases_2021['Year']= q4_cases_2021['date'].apply(lambda x: getYear(x))
q4_cases_2021 = q4_cases_2021.groupby('Year').sum().reset_index()
q4_cases_2021['Year'] = q4_cases_2021['Year'].replace('2021', 'Q4')

q_cases_2021 = q1_cases_2021.append([q2_cases_2021,q3_cases_2021,q4_cases_2021])

q1_deaths_2021['Year']= q1_deaths_2021['date'].apply(lambda x: getYear(x))
q1_deaths_2021 = q1_deaths_2021.groupby('Year').sum().reset_index()
q1_deaths_2021['Year'] = q1_deaths_2021['Year'].replace('2021', 'Q1')

q2_deaths_2021['Year']= q2_deaths_2021['date'].apply(lambda x: getYear(x))
q2_deaths_2021 = q2_deaths_2021.groupby('Year').sum().reset_index()
q2_deaths_2021['Year'] = q2_deaths_2021['Year'].replace('2021', 'Q2')

q3_deaths_2021['Year']= q3_deaths_2021['date'].apply(lambda x: getYear(x))
q3_deaths_2021 = q3_deaths_2021.groupby('Year').sum().reset_index()
q3_deaths_2021['Year'] = q3_deaths_2021['Year'].replace('2021', 'Q3')

q4_deaths_2021['Year']= q4_deaths_2021['date'].apply(lambda x: getYear(x))
q4_deaths_2021 = q4_deaths_2021.groupby('Year').sum().reset_index()
q4_deaths_2021['Year'] = q4_deaths_2021['Year'].replace('2021', 'Q4')

q_deaths_2021 = q1_deaths_2021.append([q2_deaths_2021,q3_deaths_2021,q4_deaths_2021])

q_graph_2021 = pd.merge(q_cases_2021,q_deaths_2021,on='Year')
q_table_2021 = pd.merge(q_cases_2021,q_deaths_2021,on='Year')

q_table_2021.loc['Total'] = q_table_2021.sum(numeric_only=True, axis=0)
q_table_2021['Overall Cases (%)'] = (q_table_2021['Cases Positive']/q_table_2021['Cases Positive'].sum())*200
q_table_2021['Cases Vax. (%)'] = (q_table_2021['Cases Vax.']/q_table_2021['Cases Positive'])*100
q_table_2021['Recovered (%)'] = (q_table_2021['Cases Recovered']/q_table_2021['Cases Positive'])*100
q_table_2021['Death (%)'] = (q_table_2021['Death Cases']/q_table_2021['Cases Positive'])*100
q_table_2021['Deaths Vax. (%)'] = (q_table_2021['Deaths Vax.']/q_table_2021['Death Cases'])*100
q_table_2021['Year'] = q_table_2021['Year'].replace(np.nan, 'Total')

q_table_2021 = q_table_2021[['Year','Cases Positive','Overall Cases (%)',
                                           'Cases Vax.','Cases Vax. (%)',
                                           'Cases Recovered','Recovered (%)',
                                           'Death Cases','Death (%)',
                                           'Deaths Vax.','Deaths Vax. (%)']]

q_table_2021.style.set_caption("Malaysia Covid19 Quarterly Report Year 2021").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '20px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}',
     'Death Cases':'{:,.0f}','Deaths Vax.':'{:,.0f}','Recovered (%)':'{:,.1f}',
     'Death (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Deaths Vax. (%)':'{:,.1f}',
     'Overall Cases (%)':'{:,.1f}'
    }).apply(lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[31]:
Malaysia Covid19 Quarterly Report Year 2021
Year Cases Positive Overall Cases (%) Cases Vax. Cases Vax. (%) Cases Recovered Recovered (%) Death Cases Death (%) Deaths Vax. Deaths Vax. (%)
Q1 232,490 8.8 330 0.1 240,683 103.5 801 0.3 1 0.1
Q2 406,479 15.4 15,759 3.9 353,056 86.9 3,898 1.0 309 7.9
Q3 1,493,716 56.5 672,657 45.0 1,372,144 91.9 21,162 1.4 7,747 36.6
Q4 512,391 19.4 378,417 73.9 630,555 123.1 5,155 1.0 2,768 53.7
Total 2,645,076 100.0 1,067,163 40.3 2,596,438 98.2 31,016 1.2 10,825 34.9
In [32]:
q1_cases_2022 = df_q_cases.query("date >= '2022-01-01' \
                            and date <= '2022-03-31'")
q2_cases_2022 = df_q_cases.query("date >= '2022-04-01' \
                            and date <= '2022-06-30'")
q3_cases_2022 = df_q_cases.query("date >= '2022-07-01' \
                            and date <= '2022-09-30'")
q4_cases_2022 = df_q_cases.query("date >= '2022-10-01' \
                            and date <= '2022-12-31'")

q1_deaths_2022 = df_q_deaths.query("date >= '2022-01-01' \
                            and date <= '2022-03-31'")
q2_deaths_2022 = df_q_deaths.query("date >= '2022-04-01' \
                            and date <= '2022-06-30'")
q3_deaths_2022 = df_q_deaths.query("date >= '2022-07-01' \
                            and date <= '2022-09-30'")
q4_deaths_2022 = df_q_deaths.query("date >= '2022-10-01' \
                            and date <= '2022-12-31'")

def getYear(s):
  return s.split("-")[0]

q1_cases_2022['Year']= q1_cases_2022['date'].apply(lambda x: getYear(x))
q1_cases_2022 = q1_cases_2022.groupby('Year').sum().reset_index()
q1_cases_2022['Year'] = q1_cases_2022['Year'].replace('2022', 'Q1')

q2_cases_2022['Year']= q2_cases_2022['date'].apply(lambda x: getYear(x))
q2_cases_2022 = q2_cases_2022.groupby('Year').sum().reset_index()
q2_cases_2022['Year'] = q2_cases_2022['Year'].replace('2022', 'Q2')

q3_cases_2022['Year']= q3_cases_2022['date'].apply(lambda x: getYear(x))
q3_cases_2022 = q3_cases_2022.groupby('Year').sum().reset_index()
q3_cases_2022['Year'] = q3_cases_2022['Year'].replace('2022', 'Q3')

q4_cases_2022['Year']= q4_cases_2022['date'].apply(lambda x: getYear(x))
q4_cases_2022 = q4_cases_2022.groupby('Year').sum().reset_index()
q4_cases_2022['Year'] = q4_cases_2022['Year'].replace('2022', 'Q4')

q_cases_2022 = q1_cases_2022.append([q2_cases_2022,q3_cases_2022,q4_cases_2022])

q1_deaths_2022['Year']= q1_deaths_2022['date'].apply(lambda x: getYear(x))
q1_deaths_2022 = q1_deaths_2022.groupby('Year').sum().reset_index()
q1_deaths_2022['Year'] = q1_deaths_2022['Year'].replace('2022', 'Q1')

q2_deaths_2022['Year']= q2_deaths_2022['date'].apply(lambda x: getYear(x))
q2_deaths_2022 = q2_deaths_2022.groupby('Year').sum().reset_index()
q2_deaths_2022['Year'] = q2_deaths_2022['Year'].replace('2022', 'Q2')

q3_deaths_2022['Year']= q3_deaths_2022['date'].apply(lambda x: getYear(x))
q3_deaths_2022 = q3_deaths_2022.groupby('Year').sum().reset_index()
q3_deaths_2022['Year'] = q3_deaths_2022['Year'].replace('2022', 'Q3')

q4_deaths_2022['Year']= q4_deaths_2022['date'].apply(lambda x: getYear(x))
q4_deaths_2022 = q4_deaths_2022.groupby('Year').sum().reset_index()
q4_deaths_2022['Year'] = q4_deaths_2022['Year'].replace('2022', 'Q4')

q_deaths_2022 = q1_deaths_2022.append([q2_deaths_2022,q3_deaths_2022,q4_deaths_2022])

q_graph_2022 = pd.merge(q_cases_2022,q_deaths_2022,on='Year')
q_table_2022 = pd.merge(q_cases_2022,q_deaths_2022,on='Year')

q_table_2022.loc['Total'] = q_table_2022.sum(numeric_only=True, axis=0)
q_table_2022['Overall Cases (%)'] = (q_table_2022['Cases Positive']/q_table_2022['Cases Positive'].sum())*200
q_table_2022['Cases Vax. (%)'] = (q_table_2022['Cases Vax.']/q_table_2022['Cases Positive'])*100
q_table_2022['Recovered (%)'] = (q_table_2022['Cases Recovered']/q_table_2022['Cases Positive'])*100
q_table_2022['Death (%)'] = (q_table_2022['Death Cases']/q_table_2022['Cases Positive'])*100
q_table_2022['Deaths Vax. (%)'] = (q_table_2022['Deaths Vax.']/q_table_2022['Death Cases'])*100
q_table_2022['Year'] = q_table_2022['Year'].replace(np.nan, 'Total')

q_table_2022 = q_table_2022[['Year','Cases Positive','Overall Cases (%)',
                                           'Cases Vax.','Cases Vax. (%)',
                                           'Cases Recovered','Recovered (%)',
                                           'Death Cases','Death (%)',
                                           'Deaths Vax.','Deaths Vax. (%)']]

q_table_2022.style.set_caption("Malaysia Covid19 Quarterly Report Year 2022").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '20px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}',
     'Death Cases':'{:,.0f}','Deaths Vax.':'{:,.0f}','Recovered (%)':'{:,.1f}',
     'Death (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Deaths Vax. (%)':'{:,.1f}',
     'Overall Cases (%)':'{:,.1f}'
    }).apply(lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[32]:
Malaysia Covid19 Quarterly Report Year 2022
Year Cases Positive Overall Cases (%) Cases Vax. Cases Vax. (%) Cases Recovered Recovered (%) Death Cases Death (%) Deaths Vax. Deaths Vax. (%)
Q1 1,443,833 87.4 1,207,925 83.7 1,274,704 88.3 3,496 0.2 2,383 68.2
Q2 207,283 12.6 177,529 85.6 322,931 155.8 482 0.2 225 46.7
Total 1,651,116 100.0 1,385,454 83.9 1,597,635 96.8 3,978 0.2 2,608 65.6
In [33]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))
#Graph 1
fig.append_trace(go.Bar(x = q_graph_2020['Year'], y = q_graph_2020['Cases Positive'],
                        name='Cases Positive',marker_color='red'),row=1, col=1)
fig.append_trace(go.Bar(x = q_graph_2020['Year'], y = q_graph_2020['Cases Recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=1)
#Graph 2
fig.append_trace(go.Bar(x = q_graph_2021['Year'], y = q_graph_2021['Cases Positive'],
                        name='Cases Positive',marker_color='red'),row=1, col=2)
fig.append_trace(go.Bar(x = q_graph_2021['Year'], y = q_graph_2021['Cases Recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=2)
#Graph 3
fig.append_trace(go.Bar(x = q_graph_2022['Year'], y = q_graph_2022['Cases Positive'],
                        name='Cases Positive',marker_color='red'),row=1, col=3)
fig.append_trace(go.Bar(x = q_graph_2022['Year'], y = q_graph_2022['Cases Recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=3)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False)
fig.update_layout(height=400,showlegend=False,title_text='Covid19 Quarterly Report: Positive VS Recovered Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [34]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))
#Graph 1
fig.append_trace(go.Bar(x = q_graph_2020['Year'], y = q_graph_2020['Death Cases'],
                        name='Death Cases',marker_color='red'),row=1, col=1)
fig.append_trace(go.Bar(x = q_graph_2020['Year'], y = q_graph_2020['Deaths Vax.'],
                        name='Deaths Vax.',marker_color='blue'),row=1, col=1)
#Graph 2
fig.append_trace(go.Bar(x = q_graph_2021['Year'], y = q_graph_2021['Death Cases'],
                        name='Death Cases',marker_color='red'),row=1, col=2)
fig.append_trace(go.Bar(x = q_table_2021['Year'], y = q_graph_2021['Deaths Vax.'],
                        name='Deaths Vax.',marker_color='blue'),row=1, col=2)
#Graph 3
fig.append_trace(go.Bar(x = q_graph_2022['Year'], y = q_graph_2022['Death Cases'],
                        name='Death Cases',marker_color='red'),row=1, col=3)
fig.append_trace(go.Bar(x = q_graph_2022['Year'], y = q_graph_2022['Deaths Vax.'],
                        name='Deaths Vax.',marker_color='blue'),row=1, col=3)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False)
fig.update_layout(height=400,showlegend=False,title_text='Covid19 Quarterly Report: Deaths Cases New VS Vax.', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [35]:
fig = make_subplots(shared_xaxes=True, specs=[[{'secondary_y': True}]])

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_new'], name ='Positive Cases', 
               line = dict(color='blue', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_recovered'], name = 'Recovered Cases',
               line = dict(color='red', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['total_vax'], name = 'Vax. Cases',
               line = dict(color='green', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_new'], name ='Cumulative Cases', 
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_recovered'], name = 'Cumulative Recovered',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_vax'], name = 'Cumulative Vax.',
               line = dict(color='green', width=1)), secondary_y=False, row=1, col=1)

fig.update_layout(title_text='Malaysia Covid19 New And Recovered Cases', title_x=0.5, showlegend=False,
                 height=600)
fig.update_xaxes(title_text='')
fig.update_annotations(font=dict(family="Helvetica", size=12))
fig.update_layout(font=dict(family="Helvetica", size=14))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-10-11', x1='2021-10-11',  y0=0, y1=1000000)
#fig.add_annotation(text='90% Vax.', x='2021-10-11', y=1000000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2020-09-26', x1='2020-09-26',  y0=0, y1=500000)
#fig.add_annotation(text='PRN Sabah', x='2020-09-26', y=500000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-11-20', x1='2021-11-20',  y0=0, y1=500000)
#fig.add_annotation(text='PRN Melaka', x='2021-11-20', y=500000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-12-06', x1='2021-12-06',  y0=0, y1=400000)
#fig.add_annotation(text='PRN Sarawak', x='2021-12-06', y=400000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-01-12', x1='2021-01-12',  y0=0, y1=600000)
#fig.add_annotation(text='Darurat Mula', x='2021-01-12', y=600000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-08-01', x1='2021-08-01',  y0=0, y1=1100000)
#fig.add_annotation(text='Darurat Tamat', x='2021-08-01', y=1100000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
fig.show()
In [36]:
fig = make_subplots(shared_xaxes=True, specs=[[{'secondary_y': True}]])

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['deaths_new'], name ='Death Cases', 
               line = dict(color='blue', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['total_vax'], name = 'Vax Death Cases',
               line = dict(color='red', width=1)), secondary_y=True, row=1, col=1)

fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['cum_deaths'], name ='Cum. Death Cases', 
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['cum_vax'], name = 'Cum. Vax Death Recovered',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)


fig.update_layout(title_text='Malaysia Covid19 Death Cases: New VS Vax', title_x=0.5, showlegend=False,
                 height=600)
fig.update_xaxes(title_text='')
fig.update_annotations(font=dict(family="Helvetica", size=12))
fig.update_layout(font=dict(family="Helvetica", size=14))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.show()
In [37]:
new_cases = df_mas_cases.tail(1)
new_deaths = df_mas_deaths.tail(1)
In [38]:
#Creating the main key points from the datasets
print('Key Points Highlights:-')
print('-----------------------------------------------------------------')
print('1. Total Positive Cases                  :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Positive']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases (%)']),'%')
print('2. New Positive Cases                    :','{0:,.0f}'.format(new_cases.at[new_cases.index[0],'cases_new']))
print('3. Total Positive Cases After Vaccinated :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Vax.']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases Vax. (%)']),'%')
print('4. Total Recovered Cases                 :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Recovered']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases Recovered (%)']),'%')
print('5. New Recovered Cases                   :','{0:,.0f}'.format(new_cases.at[new_cases.index[0],'cases_recovered']))
print('6. Total Death Cases                     :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Death Cases']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Deaths (%)']),'%')
print('7. New Death Cases                       :','{0:,.0f}'.format(new_deaths.at[new_deaths.index[0],'deaths_new']))
print('8. Total Death Cases After Vaccinated    :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Deaths Vax.']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Deaths Vax. (%)']),'%')
print('9. Total 1 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_partial']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 1D (%)']),'%')
print('10. Total 2 Dose Vaccinated              :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_full']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 2D (%)']),'%')
print('11. Total 3 Dose Vaccinated              :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_booster']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 3D (%)']),'%')
print('-----------------------------------------------------------------')
Key Points Highlights:-
-----------------------------------------------------------------
1. Total Positive Cases                  : 4,409,202 / 13.5 %
2. New Positive Cases                    : 6,968
3. Total Positive Cases After Vaccinated : 2,452,617 / 55.6 %
4. Total Recovered Cases                 : 4,283,013 / 97.1 %
5. New Recovered Cases                   : 8,267
6. Total Death Cases                     : 35,465 / 0.8 %
7. New Death Cases                       : 16
8. Total Death Cases After Vaccinated    : 13,433 / 37.9 %
9. Total 1 Dose Vaccinated               : 27,430,337 / 84.0 %
10. Total 2 Dose Vaccinated              : 26,327,040 / 80.6 %
11. Total 3 Dose Vaccinated              : 15,985,545 / 48.9 %
-----------------------------------------------------------------
In [39]:
df_states_table.drop(['daily_partial','daily_full','pop','daily','daily_booster'],axis='columns',inplace=True)
In [40]:
#df_states_table.drop(['Cases Vax.','Death BID','Deaths Vax.'],axis='columns',inplace=True)
df_states_table['Overall Cases (%)'] = (df_states_table['Cases Positive']/df_states_table['Cases Positive'].sum())*200
df_states_table = df_states_table[['States','Cases Positive','Overall Cases (%)',
                                   'Cases (%)','Cases Vax. (%)',
                                   'Cases Recovered','Cases Recovered (%)',
                                   'Death Cases','Deaths (%)',
                                   'Deaths Vax. (%)','Deaths BID (%)',
                                   'Vax. 3D (%)','Vax. 2D (%)','Vax. 1D (%)']]
df_states_table = df_states_table.sort_values('Cases Positive',ascending=False)
df_states_table.style.set_caption("Malaysia Details Of Covid19 Cases At Each States").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}',
     'Death Cases':'{:,.0f}','Deaths (%)':'{:,.1f}','Deaths BID':'{:,.0f}',
     'Deaths Vax.':'{:,.0f}','Cases (%)':'{:,.1f}','Cases Recovered (%)':'{:,.1f}',
     'Cases Vax. (%)':'{:,.1f}','Vax. 2D (%)':'{:,.1f}','Vax. 1D (%)':'{:,.1f}',
     'Deaths Vax. (%)':'{:,.1f}','Deaths BID (%)':'{:,.1f}','Vax. 3D (%)':'{:,.1f}',
     'Overall Cases (%)':'{:,.1f}'}
).set_properties(subset=['States'],**{'text-align': 'left'}).apply(
    lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[40]:
Malaysia Details Of Covid19 Cases At Each States
States Cases Positive Overall Cases (%) Cases (%) Cases Vax. (%) Cases Recovered Cases Recovered (%) Death Cases Deaths (%) Deaths Vax. (%) Deaths BID (%) Vax. 3D (%) Vax. 2D (%) Vax. 1D (%)
Malaysia 4,409,202 100.0 13.5 55.6 4,283,013 97.1 35,465 0.8 37.9 21.2 48.9 80.6 84.0
Selangor 1,318,085 29.9 20.1 55.5 1,255,698 95.3 10,607 0.8 34.7 21.6 61.4 74.9 78.5
Johor 380,942 8.6 10.0 52.6 372,045 97.7 4,497 1.2 42.4 13.6 55.6 82.5 86.8
Sabah 370,132 8.4 9.7 51.9 358,640 96.9 3,120 0.8 26.2 40.7 23.7 63.6 63.7
W.P. Kuala Lumpur 343,469 7.8 19.7 54.8 333,769 97.2 2,814 0.8 36.0 26.0 98.3 176.7 184.5
Sarawak 304,281 6.9 10.8 59.8 300,936 98.9 1,725 0.6 50.9 21.8 55.4 78.8 85.6
Kedah 297,680 6.8 13.6 57.2 293,711 98.7 2,615 0.9 38.7 17.9 33.5 73.3 75.7
Pulau Pinang 275,534 6.2 15.5 60.7 271,947 98.7 1,976 0.7 42.5 21.6 60.3 88.3 91.1
Kelantan 247,112 5.6 12.8 55.1 245,072 99.2 1,419 0.6 36.0 28.0 16.9 62.0 63.7
Negeri Sembilan 199,492 4.5 17.7 52.1 193,715 97.1 1,471 0.7 32.6 12.6 58.0 86.1 89.9
Perak 198,691 4.5 7.9 54.4 193,311 97.3 1,905 1.0 49.8 15.5 45.9 76.4 79.0
Pahang 170,202 3.9 10.1 58.5 167,814 98.6 968 0.6 40.3 13.2 36.8 71.5 74.1
Terengganu 125,360 2.8 9.8 58.0 122,902 98.0 859 0.7 44.5 12.8 27.4 70.0 71.9
Melaka 120,938 2.7 12.9 53.5 117,184 96.9 1,110 0.9 41.3 14.6 57.6 79.6 82.7
W.P. Labuan 21,251 0.5 21.2 48.5 21,046 99.0 155 0.7 11.0 28.4 49.3 81.0 88.2
W.P. Putrajaya 18,844 0.4 16.2 61.8 18,361 97.4 42 0.2 52.4 2.4 71.0 129.1 139.3
Perlis 17,189 0.4 6.7 71.9 16,862 98.1 182 1.1 46.7 4.4 30.7 81.5 84.0
In [41]:
df_states_graph = df_states
df_states_graph['vaksin_percentage_partial'] = df_states_graph['daily_partial']/df_states_graph['pop']*100
df_states_graph['vaksin_percentage_full'] = df_states_graph['daily_full']/df_states_graph['pop']*100
df_states_graph['deaths_vax_total'] = df_states_graph['deaths_pvax'] + df_states_graph['deaths_fvax']
df_states_graph['cases_vax_total'] = df_states_graph['cases_pvax'] + df_states_graph['cases_fvax']
In [42]:
df_mas_deaths['deaths_vax_total'] = df_mas_deaths['deaths_pvax'] + df_mas_deaths['deaths_fvax'] + df_mas_deaths['deaths_boost']
df_mas['deaths_vax_total'] = df_mas['deaths_pvax'] + df_mas['deaths_fvax'] + df_mas['deaths_boost']
df_mas_test['total_test'] = df_mas_test['rtk-ag'] + df_mas_test['pcr']
df_mas_test['cum_total'] = df_mas_test['total_test'].cumsum()
In [43]:
df_mas_new = df_mas[['date','cases_new','deaths_new']]
df_mas_new['cases_new_7'] = df_mas_new['cases_new'].shift(7)
df_mas_new['cases_new_14'] = df_mas_new['cases_new'].shift(14)
df_mas_new['cases_new_21'] = df_mas_new['cases_new'].shift(21)
df_mas_new['deaths_new_7'] = df_mas_new['deaths_new'].shift(7)
df_mas_new['deaths_new_14'] = df_mas_new['deaths_new'].shift(14)
df_mas_new['deaths_new_21'] = df_mas_new['deaths_new'].shift(21)
df_mas_new = df_mas_new.tail(7)
df_mas_new['cum_new'] = df_mas_new['cases_new'].cumsum()
df_mas_new['cum_new_7'] = df_mas_new['cases_new_7'].cumsum()
df_mas_new['cum_new_14'] = df_mas_new['cases_new_14'].cumsum()
df_mas_new['cum_new_21'] = df_mas_new['cases_new_21'].cumsum()
df_mas_new['cum_deaths_new'] = df_mas_new['deaths_new'].cumsum()
df_mas_new['cum_deaths_7'] = df_mas_new['deaths_new_7'].cumsum()
df_mas_new['cum_deaths_14'] = df_mas_new['deaths_new_14'].cumsum()
df_mas_new['cum_deaths_21'] = df_mas_new['deaths_new_21'].cumsum()
In [44]:
print('Four Weeks Cumulative Daily Cases Comparison Analysis:-')
print('--------------------------------------------')
print('Average Week 1: ', '{0:,.0f}'.format(df_mas_new['cum_new'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new'].mean()-df_mas_new['cum_new_7'].mean()),'diff.)')
print('Average Week 2: ', '{0:,.0f}'.format(df_mas_new['cum_new_7'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new_7'].mean()-df_mas_new['cum_new_14'].mean()),'diff.)')
print('Average Week 3: ', '{0:,.0f}'.format(df_mas_new['cum_new_14'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new_14'].mean()-df_mas_new['cum_new_21'].mean()),'diff.)')
print('Average Week 4: ', '{0:,.0f}'.format(df_mas_new['cum_new_21'].mean()), '-')
print('--------------------------------------------')
print('Four Weeks Daily Cases Comparison Analysis:-')
print('--------------------------------------------')
print('Average Week 1:', '{0:,.0f}'.format(df_mas_new['cases_new'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new'].mean()-df_mas_new['cases_new_7'].mean()),'diff.)')
print('Average Week 2:', '{0:,.0f}'.format(df_mas_new['cases_new_7'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new_7'].mean()-df_mas_new['cases_new_14'].mean()),'diff.)')
print('Average Week 3:', '{0:,.0f}'.format(df_mas_new['cases_new_14'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new_14'].mean()-df_mas_new['cases_new_21'].mean()),'diff.)')
print('Average Week 4:', '{0:,.0f}'.format(df_mas_new['cases_new_21'].mean()), '-')
print('--------------------------------------------')
Four Weeks Cumulative Daily Cases Comparison Analysis:-
--------------------------------------------
Average Week 1:  37,178 ( -8,671 diff.)
Average Week 2:  45,849 ( -16,759 diff.)
Average Week 3:  62,608 ( -21,491 diff.)
Average Week 4:  84,099 -
--------------------------------------------
Four Weeks Daily Cases Comparison Analysis:-
--------------------------------------------
Average Week 1: 8,525 ( -2,057 diff.)
Average Week 2: 10,582 ( -3,856 diff.)
Average Week 3: 14,438 ( -4,845 diff.)
Average Week 4: 19,283 -
--------------------------------------------
In [45]:
fig = make_subplots(rows=1, cols=4, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>New Confirmed Cases Daily</b>',
                                   '<b>New Confirmed Cases Cumulative</b>',
                                   '<b>New Deaths Cases Daily</b>',
                                   '<b>New Deaths Cases Cumulative</b>'))
#Graph 1
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new'],name='Week 1', mode="lines",
                           line = dict(color='red',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple',width=0.5)),row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=1)
#Graph 2
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new'],name='Week 1', mode="lines",
                           line = dict(color='red',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple',width=0.5)),row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="top left",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=2)
#Graph 3
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new'],name='Week 1', mode="lines",
                           line = dict(color='red', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple', width=0.5)),row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=3)
#Graph 4
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_new'],name='Week 1', mode="lines",
                           line = dict(color='red', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_7'],name='Week 2', mode="lines",
                           line = dict(color='blue', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_14'],name='Week 3', mode="lines",
                           line = dict(color='green', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_21'],name='Week 4', mode="lines",
                           line = dict(color='purple', width=0.5)),row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="top right",row=1, col=4)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False,title_text="Malaysia Covid19 Latest Cases In Details (4 Week Comparison)", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black',
                visible=True, showticklabels=False)
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [46]:
df_mas_cases['cum_new'] = df_mas_cases['cases_new'].cumsum()
df_mas_cases['cum_recovered'] = df_mas_cases['cases_recovered'].cumsum()
df_mas_deaths['cum_deaths'] = df_mas_deaths['deaths_new'].cumsum()
df_mas_deaths['cum_deaths_vax'] = df_mas_deaths['deaths_vax_total'].cumsum()
In [47]:
fig = make_subplots(rows=2, cols=4, shared_xaxes=True, vertical_spacing=0.08,
                    specs=[[{'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}], 
                           [{'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],

subplot_titles=('<b>Cases: Total VS Recover</b>',
                '<b>ICU Daily Admitted</b>',
                '<b>Hosp.: Admit VS Discharge</b>',
                '<b>PKRC: Admitted VS Discharged</b>',
                '<b>Deaths: Total, BID & Vax.</b>',
                '<b>Total Daily Covid19 Test</b>',
                '<b>States Hosp. Admission & Discharge</b>',
                '<b>States Vax. (%): 1D VS 2D</b>'))

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_new'], name='Positive Cases',
                           line = dict(color='red',width=0.5)), row=1, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_new'], name='Positive Cases',
                           line = dict(color='red',width=1)), row=1, col=1, secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_recovered'],name='Recovered Cases',
                            line = dict(color='blue',width=0.5)),row=1, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_recovered'],name='Recovered Cases',
                            line = dict(color='blue',width=1)),row=1, col=1, secondary_y=False)
fig.add_hline(y=df_mas_cases['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Cases", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_cases['cases_recovered'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Recovered", annotation_position="top left",row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_icu_daily['date'], y = df_icu_daily['icu_covid'],name='ICU Covid',
                           line = dict(color='blue', width=0.5)),row=1, col=2, secondary_y=True)
fig.add_trace(go.Scatter(x = df_icu_daily['date'], y = df_icu_daily['icu_covid_cum'],name='ICU Covid',
                           line = dict(color='red', width=0.5)),row=1, col=2, secondary_y=False)
fig.add_hline(y = df_icu_daily['icu_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily", annotation_position="bottom left",row=1, col=2)
fig.add_hline(y = df_icu_daily['icu_covid_cum'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Cum.", annotation_position="bottom left",row=1, col=2)
# Graph 3
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_new'],name='Deaths Cases',
                           line = dict(width=0.5, color='blue')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['cum_deaths'],name='Deaths Cases',
                           line = dict(width=1, color='blue')),row=2, col=1, secondary_y=False)
fig.add_hline(y=df_mas_deaths['deaths_new'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily Deaths", annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_bid_dod'],name='BID Cases',
                           line = dict(width=0.5, color='red')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_vax_total'],name='Deaths Vaccinated Cases',
                            line = dict(width=0.5, color='black')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['cum_deaths_vax'],name='Deaths Vaccinated Cases',
                            line = dict(width=1, color='black')),row=2, col=1, secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mas_test['date'], y = df_mas_test['total_test'],name='Daily Covid19 Test',
                           line = dict(color='blue', width=0.5)),row=2, col=2, secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_test['date'], y = df_mas_test['cum_total'],name='Cumulative Covid19 Test',
                           line = dict(color='red', width=1)),row=2, col=2, secondary_y=True)
fig.add_hline(y=df_mas_test['total_test'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily Test", annotation_position="top left",row=2, col=2)
#Graph 5
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['admitted_covid'],name='Admitted',
                           line = dict(color='blue', width=0.5)),row=1, col=3, secondary_y=True)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['discharged_covid'],name='Discharged',
                           line = dict(color='red', width=0.5)),row=1, col=3, secondary_y=True)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['admitted_covid_cum'],name='Admitted',
                           line = dict(color='blue', width=1)),row=1, col=3, secondary_y=False)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['discharged_covid_cum'],name='Discharged',
                           line = dict(color='red', width=1)),row=1, col=3, secondary_y=False)
fig.add_hline(y = df_hosp_daily['admitted_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Admitted", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y = df_hosp_daily['discharged_covid'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Discharged", annotation_position="top left",row=1, col=3)
#Graph 6
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['admitted_covid'],name='Admitted',
                           line = dict(color='blue', width=0.5)),row=1, col=4, secondary_y=True)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['discharged_covid'],name='Discharged',
                           line = dict(color='red', width=0.5)),row=1, col=4, secondary_y=True)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['admitted_covid_cum'],name='Admitted',
                           line = dict(color='blue', width=1)),row=1, col=4, secondary_y=False)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['discharged_covid_cum'],name='Discharged',
                           line = dict(color='red', width=1)),row=1, col=4, secondary_y=False)
fig.add_hline(y = df_pkrc_daily['admitted_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Admitted", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y = df_pkrc_daily['discharged_covid'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Discharged", annotation_position="top left",row=1, col=4)
#Graph 7
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['admitted_covid'],name='Admitted Cases',
                       marker_color='blue'),row=2, col=3, secondary_y=False)
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['discharged_covid'],name='Discharged Cases',
                       marker_color='red'),row=2, col=3, secondary_y=False)
#Graph 8
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['vaksin_percentage_partial'],
                        name='Partial Vaksin (%)',marker_color='blue'),row=2, col=4, secondary_y=False)
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['vaksin_percentage_full'],
                        name='Full Vaksin (%)',marker_color='red'),row=2, col=4, secondary_y=False)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=600,showlegend=False,title_text="Malaysia Covid19 Cases Overview", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

# add a horizontal line & annotations
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0=0, x1=16, xref="paper", y0=90, y1=90, yref="y",row=2, col=4)
fig.add_annotation(text='90% Vax. Pop.', x=6, y=90, arrowhead=1, showarrow=True,row=2, col=4)
#Plotting the graph
fig.show()
In [48]:
fig = make_subplots(rows=1, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Total Daily Vax.</b>',
                '<b>Cumulative Daily Vax.</b>',
                '<b>Full, Partial & Booster</b>',
                '<b>Pfizer, Sinovac, AZ & Cansino</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily'],name='Total Daily Vaccinated',
                           line = dict(color='red',width=0.5)),row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Vax. (%)'],name='Vax. (%)',
                           line = dict(color='blue',width=0.5)),row=1, col=1,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Cum. Daily'],name='Cum. Daily Vaccinated',
                           line = dict(color='red',width=0.5)),row=1, col=2,secondary_y=False)
fig.add_hline(y=df_mas_vaksin['Cum. Daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Cum. Vax.", annotation_position="top left",row=1, col=2)
#Grpah 3
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_partial'],name='Partial',
                           line = dict(color='red',width=0.5)),row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_full'],name='Full',
                           line = dict(color='blue',width=0.5)),row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_booster'],name='Booster',
                           line = dict(color='green',width=0.5)),row=1, col=3,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=3)
#Graph 4
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total Pfizer'],name='Pfizer',
                           line = dict(color='red',width=0.5)),row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total Sinovac'],name='Sinovac',
                           line = dict(color='blue',width=0.5)),row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total AstraZ'],name='Astra Zaneca',
                           line = dict(color='green',width=0.5)),row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['cansino'],name='Cansino',
                           line = dict(color='black',width=0.5)),row=1, col=4,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=4)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False,title_text="Daily Vaccination Details", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [49]:
#Forecasting of New Cases VS Recovered Cases
#Importing the required module
#from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
#from statsmodels.tsa.statespace.varmax import VARMAX
#from statsmodels.tsa.api import VAR
#from statsmodels.tsa.stattools import grangercausalitytests, adfuller
#from tqdm import tqdm_notebook
#from itertools import product
#import statsmodels.api as sm
#import warnings
#warnings.filterwarnings('ignore')
#Importing the required datasets
#filepath_cases = 'https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv'
#filepath_deaths = "https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_malaysia.csv"
#filepath_vaksin = 'https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_malaysia.csv'
#Preparing the required datasets
#filepath_cases = pd.read_csv(filepath_cases, parse_dates=['date'], index_col='date').astype('float64')
#filepath_deaths = pd.read_csv(filepath_deaths, parse_dates=['date'], index_col='date').astype('float64')
#filepath_vaksin = pd.read_csv(filepath_vaksin, parse_dates=['date'], index_col='date').astype('float64')
#macro_data = pd.merge(filepath_cases,filepath_deaths,on='date')
#macro_data = pd.merge(macro_data,filepath_vaksin,on='date')
#macro_data['cases_vax_total'] = macro_data['cases_pvax'] + macro_data['cases_fvax']
#macro_data['deaths_vax_total'] = macro_data['deaths_pvax'] + macro_data['deaths_fvax']
#macro_data = macro_data[['cases_new','cases_active']]
#train_df=macro_data[:-12]
#test_df=macro_data[-360:]
#model = VAR(train_df.diff()[1:])
#sorted_order=model.select_order(maxlags=30)
#var_model = VARMAX(train_df, order=(4,0),enforce_stationarity= False)
#fitted_model = var_model.fit(disp=True)
#Creating the required forecast
#n_forecast = 180
#predict = fitted_model.get_prediction(start=len(train_df),end=len(train_df) + n_forecast-1)
#predictions=predict.predicted_mean
#predictions.columns=['cases_predicted','cases_active_predicted']
#test_vs_pred=pd.concat([test_df,predictions],axis=1)
#test_vs_pred = test_vs_pred.reset_index()
#test_vs_pred['cases_new_cum'] = test_vs_pred['cases_new'].cumsum()
#test_vs_pred['cases_active_cum'] = test_vs_pred['cases_active'].cumsum()
#test_vs_pred['cases_predicted_cum'] = test_vs_pred['cases_predicted'].cumsum()
#test_vs_pred['cases_active_predicted_cum'] = test_vs_pred['cases_active_predicted'].cumsum()
#Plotting the required forecast
#fig = make_subplots(specs=[[{'secondary_y': True}]])
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_new'], name ='Positive Cases', line = dict(color='blue', width=1)), secondary_y=True)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_new_cum'], name ='Positive Cases', line = dict(color='blue', width=1)), secondary_y=False)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_active'], name = 'Positive Cases After Vaccinated',line = dict(color='red', width=1)), secondary_y=True)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_active_cum'], name = 'Positive Cases After Vaccinated',line = dict(color='red', width=1)), secondary_y=False)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_predicted'], name = 'Predicted Positive Cases',line = dict(color='blue', width=0.75)), secondary_y=True)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_active_predicted'], name = 'Predicted Positive Cases After Vaccinated',line = dict(color='red', width=0.75)), secondary_y=True)


#fig.update_layout(title_text='Malaysia Covid19 Forecast of Positive & Active Cases (Based on VAR Model)', title_x=0.5,showlegend=False, height=600)
#fig.update_xaxes(title_text='')
#fig.update_annotations(font=dict(family="Helvetica", size=12))
#fig.update_layout(font=dict(family="Helvetica", size=14))
#fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", x0='2021-10-11', x1='2021-10-11',  y0=0, y1=800000)
#fig.add_annotation(text='90% Adult Vax.', x='2021-10-11', y=800000, arrowhead=3, align='center', arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", x0='2021-11-20', x1='2021-11-20',  y0=0, y1=600000)
#fig.add_annotation(text='PRN Melaka', x='2021-11-20', y=600000, arrowhead=3, align='center', arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", x0='2021-12-06', x1='2021-12-06',  y0=0, y1=500000)
#fig.add_annotation(text='PRN Sarawak', x='2021-12-06', y=500000, arrowhead=3, align='center', arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, xanchor="left", yanchor="bottom")
#fig.show()
In [50]:
df = df_states_cases
df_joh = df[df.state == 'Johor']
df_ked = df[df.state == 'Kedah']
df_kel = df[df.state == 'Kelantan']
df_mel = df[df.state == 'Melaka']
df_neg = df[df.state == 'Negeri Sembilan']
df_pah = df[df.state == 'Pahang']
df_prk = df[df.state == 'Perak']
df_per = df[df.state == 'Perlis']
df_pen = df[df.state == 'Pulau Pinang']
df_sab = df[df.state == 'Sabah']
df_sar = df[df.state == 'Sarawak']
df_sel = df[df.state == 'Selangor']
df_ter = df[df.state == 'Terengganu']
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_lab = df[df.state == 'W.P. Labuan']
df_put = df[df.state == 'W.P. Putrajaya']
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_hline(y=df_joh['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=1)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_hline(y=df_ked['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=2)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_hline(y=df_kel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=3)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_hline(y=df_mel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=4)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_hline(y=df_neg['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_hline(y=df_pah['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=2)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_hline(y=df_prk['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=3)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_hline(y=df_per['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=4)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_hline(y=df_pen['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=1)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_hline(y=df_sab['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=2)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_hline(y=df_sar['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=3)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_hline(y=df_sel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=4)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_hline(y=df_ter['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=1)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_hline(y=df_kul['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=2)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_hline(y=df_lab['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=3)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_hline(y=df_put['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=4)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Cases & Recovered At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [51]:
df = df_states_deaths
df['deaths_vax_total'] = df['deaths_fvax'] + df['deaths_pvax'] + df['deaths_boost'] 
df_joh = df[df.state == 'Johor']
df_ked = df[df.state == 'Kedah']
df_kel = df[df.state == 'Kelantan']
df_mel = df[df.state == 'Melaka']
df_neg = df[df.state == 'Negeri Sembilan']
df_pah = df[df.state == 'Pahang']
df_prk = df[df.state == 'Perak']
df_per = df[df.state == 'Perlis']
df_pen = df[df.state == 'Pulau Pinang']
df_sab = df[df.state == 'Sabah']
df_sar = df[df.state == 'Sarawak']
df_sel = df[df.state == 'Selangor']
df_ter = df[df.state == 'Terengganu']
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_lab = df[df.state == 'W.P. Labuan']
df_put = df[df.state == 'W.P. Putrajaya']
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_hline(y=df_joh['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=1)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=False)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_hline(y=df_ked['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=2)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=False)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_hline(y=df_kel['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=3)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_hline(y=df_mel['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=4)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=False)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_hline(y=df_neg['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=False)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_hline(y=df_pah['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=2)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=False)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_hline(y=df_prk['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=3)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=False)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_hline(y=df_per['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=4)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=False)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_hline(y=df_pen['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=1)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=False)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_hline(y=df_sab['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=2)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=False)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_hline(y=df_sar['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=3)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=False)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_hline(y=df_sel['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=4)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=False)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_hline(y=df_ter['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=1)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=False)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_hline(y=df_kul['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=2)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=False)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_hline(y=df_lab['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=3)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=False)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['deaths_new'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_hline(y=df_put['deaths_new'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=4)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=False)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Daily Deaths Total & Vaccinated At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [52]:
#Extracting And Separating Data For Each States
#Johor
df = df_states_vaksin
df_joh = df[df.state == 'Johor']
df_joh['cum_partial'] = df_joh['daily_partial'].cumsum()
df_joh['cum_full'] = df_joh['daily_full'].cumsum()
df_joh['cum_booster'] = df_joh['daily_booster'].cumsum()
#Kedah
df_ked = df[df.state == 'Kedah']
df_ked['cum_partial'] = df_ked['daily_partial'].cumsum()
df_ked['cum_full'] = df_ked['daily_full'].cumsum()
df_ked['cum_booster'] = df_ked['daily_booster'].cumsum()
#Kelantan
df_kel = df[df.state == 'Kelantan']
df_kel['cum_partial'] = df_kel['daily_partial'].cumsum()
df_kel['cum_full'] = df_kel['daily_full'].cumsum()
df_kel['cum_booster'] = df_kel['daily_booster'].cumsum()
#Melaka
df_mel = df[df.state == 'Melaka']
df_mel['cum_partial'] = df_mel['daily_partial'].cumsum()
df_mel['cum_full'] = df_mel['daily_full'].cumsum()
df_mel['cum_booster'] = df_mel['daily_booster'].cumsum()
#Negeri Sembilan
df_neg = df[df.state == 'Negeri Sembilan']
df_neg['cum_partial'] = df_neg['daily_partial'].cumsum()
df_neg['cum_full'] = df_neg['daily_full'].cumsum()
df_neg['cum_booster'] = df_neg['daily_booster'].cumsum()
#Pahang
df_pah = df[df.state == 'Pahang']
df_pah['cum_partial'] = df_pah['daily_partial'].cumsum()
df_pah['cum_full'] = df_pah['daily_full'].cumsum()
df_pah['cum_booster'] = df_pah['daily_booster'].cumsum()
#Perak
df_prk = df[df.state == 'Perak']
df_prk['cum_partial'] = df_prk['daily_partial'].cumsum()
df_prk['cum_full'] = df_prk['daily_full'].cumsum()
df_prk['cum_booster'] = df_prk['daily_booster'].cumsum()
#Perlis
df_per = df[df.state == 'Perlis']
df_per['cum_partial'] = df_per['daily_partial'].cumsum()
df_per['cum_full'] = df_per['daily_full'].cumsum()
df_per['cum_booster'] = df_per['daily_booster'].cumsum()
#Pulau Pinang
df_pen = df[df.state == 'Pulau Pinang']
df_pen['cum_partial'] = df_pen['daily_partial'].cumsum()
df_pen['cum_full'] = df_pen['daily_full'].cumsum()
df_pen['cum_booster'] = df_pen['daily_booster'].cumsum()
#Sabah
df_sab = df[df.state == 'Sabah']
df_sab['cum_partial'] = df_sab['daily_partial'].cumsum()
df_sab['cum_full'] = df_sab['daily_full'].cumsum()
df_sab['cum_booster'] = df_sab['daily_booster'].cumsum()
#Sarawak
df_sar = df[df.state == 'Sarawak']
df_sar['cum_partial'] = df_sar['daily_partial'].cumsum()
df_sar['cum_full'] = df_sar['daily_full'].cumsum()
df_sar['cum_booster'] = df_sar['daily_booster'].cumsum()
#Selangor
df_sel = df[df.state == 'Selangor']
df_sel['cum_partial'] = df_sel['daily_partial'].cumsum()
df_sel['cum_full'] = df_sel['daily_full'].cumsum()
df_sel['cum_booster'] = df_sel['daily_booster'].cumsum()
#Terengganu
df_ter = df[df.state == 'Terengganu']
df_ter['cum_partial'] = df_ter['daily_partial'].cumsum()
df_ter['cum_full'] = df_ter['daily_full'].cumsum()
df_ter['cum_booster'] = df_ter['daily_booster'].cumsum()
#Kuala Lumpur
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_kul['cum_partial'] = df_kul['daily_partial'].cumsum()
df_kul['cum_full'] = df_kul['daily_full'].cumsum()
df_kul['cum_booster'] = df_kul['daily_booster'].cumsum()
#Labuan
df_lab = df[df.state == 'W.P. Labuan']
df_lab['cum_partial'] = df_lab['daily_partial'].cumsum()
df_lab['cum_full'] = df_lab['daily_full'].cumsum()
df_lab['cum_booster'] = df_lab['daily_booster'].cumsum()
#Putrajaya
df_put = df[df.state == 'W.P. Putrajaya']
df_put['cum_partial'] = df_put['daily_partial'].cumsum()
df_put['cum_full'] = df_put['daily_full'].cumsum()
df_put['cum_booster'] = df_put['daily_booster'].cumsum()
In [53]:
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=1,secondary_y=False)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=2,secondary_y=False)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=3,secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=4,secondary_y=False)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=1,secondary_y=False)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=2,secondary_y=False)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=3,secondary_y=False)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=4,secondary_y=False)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=1,secondary_y=False)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=2,secondary_y=False)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=3,secondary_y=False)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=4,secondary_y=False)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=1,secondary_y=False)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=2,secondary_y=False)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=3,secondary_y=False)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=4,secondary_y=False)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Daily Vaccination (1D, 2D & 3D) At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [54]:
dfpop = df_states_pop
#Creating new vax percentage columns at each states
#Johor
df_joh_pop = dfpop[dfpop.state == 'Johor']
df_joh_pop = df_joh_pop.at[df_joh_pop.index[0],'pop']
df_joh['2 Dos (%)'] = (df_joh['cum_full']/df_joh_pop)*100
#Kedah
df_ked_pop = dfpop[dfpop.state == 'Kedah']
df_ked_pop = df_ked_pop.at[df_ked_pop.index[0],'pop']
df_ked['2 Dos (%)'] = (df_ked['cum_full']/df_ked_pop)*100
#Kelantan
df_kel_pop = dfpop[dfpop.state == 'Kelantan']
df_kel_pop = df_kel_pop.at[df_kel_pop.index[0],'pop']
df_kel['2 Dos (%)'] = (df_kel['cum_full']/df_kel_pop)*100
#Melaka
df_mel_pop = dfpop[dfpop.state == 'Melaka']
df_mel_pop = df_mel_pop.at[df_mel_pop.index[0],'pop']
df_mel['2 Dos (%)'] = (df_mel['cum_full']/df_mel_pop)*100
#Negeri Sembilan
df_neg_pop = dfpop[dfpop.state == 'Negeri Sembilan']
df_neg_pop = df_neg_pop.at[df_neg_pop.index[0],'pop']
df_neg['2 Dos (%)'] = (df_neg['cum_full']/df_neg_pop)*100
#Pahang
df_pah_pop = dfpop[dfpop.state == 'Pahang']
df_pah_pop = df_pah_pop.at[df_pah_pop.index[0],'pop']
df_pah['2 Dos (%)'] = (df_pah['cum_full']/df_pah_pop)*100
#Perak
df_prk_pop = dfpop[dfpop.state == 'Perak']
df_prk_pop = df_prk_pop.at[df_prk_pop.index[0],'pop']
df_prk['2 Dos (%)'] = (df_prk['cum_full']/df_prk_pop)*100
#Perlis
df_per_pop = dfpop[dfpop.state == 'Perlis']
df_per_pop = df_per_pop.at[df_per_pop.index[0],'pop']
df_per['2 Dos (%)'] = (df_per['cum_full']/df_per_pop)*100
#Penang
df_pen_pop = dfpop[dfpop.state == 'Pulau Pinang']
df_pen_pop = df_pen_pop.at[df_pen_pop.index[0],'pop']
df_pen['2 Dos (%)'] = (df_pen['cum_full']/df_pen_pop)*100
#Sabah
df_sab_pop = dfpop[dfpop.state == 'Sabah']
df_sab_pop = df_sab_pop.at[df_sab_pop.index[0],'pop']
df_sab['2 Dos (%)'] = (df_sab['cum_full']/df_sab_pop)*100
#Sarawak
df_sar_pop = dfpop[dfpop.state == 'Sarawak']
df_sar_pop = df_sar_pop.at[df_sar_pop.index[0],'pop']
df_sar['2 Dos (%)'] = (df_sar['cum_full']/df_sar_pop)*100
#Selangor
df_sel_pop = dfpop[dfpop.state == 'Selangor']
df_sel_pop = df_sel_pop.at[df_sel_pop.index[0],'pop']
df_sel['2 Dos (%)'] = (df_sel['cum_full']/df_sel_pop)*100
#Terengganu
df_ter_pop = dfpop[dfpop.state == 'Terengganu']
df_ter_pop = df_ter_pop.at[df_ter_pop.index[0],'pop']
df_ter['2 Dos (%)'] = (df_ter['cum_full']/df_ter_pop)*100
#Kuala Lumpur
df_kul_pop = dfpop[dfpop.state == 'W.P. Kuala Lumpur']
df_kul_pop = df_kul_pop.at[df_kul_pop.index[0],'pop']
df_kul['2 Dos (%)'] = (df_kul['cum_full']/df_kul_pop)*100
#Labuan
df_lab_pop = dfpop[dfpop.state == 'W.P. Labuan']
df_lab_pop = df_lab_pop.at[df_lab_pop.index[0],'pop']
df_lab['2 Dos (%)'] = (df_lab['cum_full']/df_lab_pop)*100
#Putrajaya
df_put_pop = dfpop[dfpop.state == 'W.P. Putrajaya']
df_put_pop = df_put_pop.at[df_put_pop.index[0],'pop']
df_put['2 Dos (%)'] = (df_put['cum_full']/df_put_pop)*100
#Start creating the graph
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=2)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=3)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=4)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=1)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=2)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=3)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=4)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=1)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=2)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=3)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=4)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=1)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=2)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=3)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=4)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,
                  title_text="Covid19 Vaccination Against Vaccination Per Population At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [55]:
#Retrieving dataset for Covid19 for all countries
dfworld = pd.read_csv('https://raw.githubusercontent.com/datasets/covid-19/main/data/time-series-19-covid-combined.csv')
dfworld['daily_cases'] = dfworld['Confirmed'].diff()
dfworld['daily_recover'] = dfworld['Recovered'].diff()
dfworld['daily_deaths'] = dfworld['Deaths'].diff()
In [56]:
dfworld2 = pd.read_csv('https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/latest/owid-covid-latest.csv')
dfworld2 = dfworld2[dfworld2['continent'].notna()] 
dfworld2 = dfworld2[['location','total_cases','total_deaths','people_vaccinated',
                     'population','population_density','gdp_per_capita']]
dfworld2['Cases (%)'] = (dfworld2['total_cases']/dfworld2['population'])*100
dfworld2['Deaths (%)'] = (dfworld2['total_deaths']/dfworld2['total_cases'])*100
dfworld2['Vaccination (%)'] = (dfworld2['people_vaccinated']/dfworld2['population'])*100

dfworld2.rename(columns={'location':'Country','total_cases':'Total Cases','total_deaths':'Total Deaths',
                         'people_vaccinated':'People Vaccinated','population':'Population',
                         'population_density':'Population Density','gdp_per_capita':'GDP Per Kapita'},inplace=True)
In [57]:
df_asean = dfworld2.loc[dfworld2['Country'].isin(['Malaysia','Singapore','Thailand','Indonesia',
                                              'Philippines','Cambodia','Laos','Vietnam',
                                              'Myanmar','Brunei'])]
df_asean = df_asean.sort_values('Total Cases',ascending=False)
def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

df_asean.style.set_caption("Overview Of Covid19 Cases In ASEAN Countries").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[57]:
Overview Of Covid19 Cases In ASEAN Countries
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
Vietnam 10,489,319 42,975 nan 98,168,829 308.1 6,171.9 10.7 0.4 nan
Indonesia 6,041,269 155,937 198,351,438 276,361,788 145.7 11,188.7 2.2 2.6 71.8
Malaysia 4,402,234 35,449 27,643,270 32,776,195 96.3 26,808.2 13.4 0.8 84.3
Thailand 4,084,299 27,263 55,885,495 69,950,844 135.1 16,277.7 5.8 0.7 79.9
Philippines 3,683,367 59,982 nan 111,046,910 351.9 7,599.2 3.3 1.6 nan
Singapore 1,167,498 1,317 5,010,668 5,453,600 7,915.7 85,535.4 21.4 0.1 91.9
Myanmar 612,658 19,434 28,522,949 54,806,014 81.7 5,591.6 1.1 3.2 52.0
Laos 201,460 727 5,734,044 7,379,358 29.7 6,397.4 2.7 0.4 77.7
Brunei 140,364 218 412,058 441,532 81.3 71,809.3 31.8 0.2 93.3
Cambodia 136,090 3,055 14,855,108 16,946,446 90.7 3,645.1 0.8 2.2 87.7
In [58]:
#Selecting datasets for ASEAN Countries
#Malaysia
dfworld.rename(columns={'Country/Region':'Country'},inplace=True)
df_mas = dfworld[dfworld.Country == 'Malaysia']
df_mas = df_mas.reset_index(drop=True)
df_mas = df_mas.drop([0])
#Indonesia
df_ind = dfworld[dfworld.Country == 'Indonesia']
df_ind = df_ind.reset_index(drop=True)
df_ind = df_ind.drop([0])
#Philippines
df_phi = dfworld[dfworld.Country == 'Philippines']
df_phi = df_phi.reset_index(drop=True)
df_phi = df_phi.drop([0])
#Burma
df_bur = dfworld[dfworld.Country == 'Burma']
df_bur = df_bur.reset_index(drop=True)
df_bur = df_bur.drop([0])
#Singapore
df_sin = dfworld[dfworld.Country == 'Singapore']
df_sin = df_sin.reset_index(drop=True)
df_sin = df_sin.drop([0])
#Thailand
df_tha = dfworld[dfworld.Country == 'Thailand']
df_tha = df_tha.reset_index(drop=True)
df_tha = df_tha.drop([0])
#Vietnam
df_vie = dfworld[dfworld.Country == 'Vietnam']
df_vie = df_vie.reset_index(drop=True)
df_vie = df_vie.drop([0])
#Cambodia
df_cam = dfworld[dfworld.Country == 'Cambodia']
df_cam = df_cam.reset_index(drop=True)
df_cam = df_cam.drop([0])
#Brunei
df_bru = dfworld[dfworld.Country == 'Brunei']
df_bru = df_bru.reset_index(drop=True)
df_bru = df_bru.drop([0])
#Laos
df_lao = dfworld[dfworld.Country == 'Laos']
df_lao = df_lao.reset_index(drop=True)
df_lao = df_lao.drop([0])
In [59]:
#Creating the ASEAN Covid19 Cases Graphs
fig = make_subplots(rows=2, cols=5, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Malaysia</b>', '<b>Indonesia</b>', '<b>Philippines</b>', '<b>Burma</b>', '<b>Singapore</b>',
                '<b>Thailand</b>', '<b>Vietnam</b>', '<b>Cambodia</b>', '<b>Brunei</b>', '<b>Laos</b>'))
#Row 1
#Graph 1
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=5,secondary_y=True)
#Row 2
#Graph 6
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=5,secondary_y=True)

#Adding title and adjusting the layout
fig.update_layout(height=500,showlegend=False,title_text="Covid19 Total And Daily Cases At ASEAN Countries",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [60]:
#Creating the ASEAN Covid19 Cases Graphs
fig = make_subplots(rows=2, cols=5, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Malaysia</b>', '<b>Indonesia</b>', '<b>Philippines</b>', '<b>Burma</b>', '<b>Singapore</b>',
                '<b>Thailand</b>', '<b>Vietnam</b>', '<b>Cambodia</b>', '<b>Brunei</b>', '<b>Laos</b>'))
#Row 1
#Graph 1
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=5,secondary_y=True)
#Row 2
#Graph 6
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=5,secondary_y=True)

#Adding title and adjusting the layout
fig.update_layout(height=500,showlegend=False,title_text="Covid19 Total Deaths And Daily Cases At ASEAN Countries",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [61]:
dfworld_highest = dfworld2.sort_values('Total Cases',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld_highest.style.set_caption("Overview Of Top 10 Highest Covid19 Cases Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[61]:
Overview Of Top 10 Highest Covid19 Cases Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
United States 80,732,932 989,331 256,880,347 332,915,074 35.6 54,225.4 24.3 1.2 77.2
India 43,047,594 522,006 998,395,198 1,393,409,033 450.4 6,426.7 3.1 1.2 71.7
Brazil 30,275,219 662,396 182,287,352 213,993,441 25.0 14,103.5 14.1 2.2 85.2
France 27,870,086 144,456 54,034,957 67,422,000 122.6 38,605.7 41.3 0.5 80.1
Germany 23,658,211 133,308 63,731,439 83,900,471 237.0 45,229.2 28.2 0.6 76.0
United Kingdom 21,936,272 172,043 53,041,898 68,207,114 272.9 39,753.2 32.2 0.8 77.8
Russia 17,829,009 366,436 80,337,544 145,912,022 8.8 24,766.0 12.2 2.1 55.1
South Korea 16,583,220 21,520 45,014,740 51,305,184 528.0 35,938.4 32.3 0.1 87.7
Italy 15,758,002 161,893 50,749,866 60,367,471 205.9 35,220.1 26.1 1.0 84.1
Turkey 15,003,696 98,610 57,807,483 85,042,736 104.9 25,129.3 17.6 0.7 68.0
In [62]:
dfworld3 = dfworld2.sort_values('People Vaccinated',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Covid19 People Vaccinated Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[62]:
Overview Of Top 10 Highest Covid19 People Vaccinated Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
China 663,393 4,657 1,280,156,000 1,444,216,102 147.7 15,308.7 0.0 0.7 88.6
India 43,047,594 522,006 998,395,198 1,393,409,033 450.4 6,426.7 3.1 1.2 71.7
United States 80,732,932 989,331 256,880,347 332,915,074 35.6 54,225.4 24.3 1.2 77.2
Indonesia 6,041,269 155,937 198,351,438 276,361,788 145.7 11,188.7 2.2 2.6 71.8
Brazil 30,275,219 662,396 182,287,352 213,993,441 25.0 14,103.5 14.1 2.2 85.2
Pakistan 1,527,486 30,368 133,965,057 225,199,929 255.6 5,034.7 0.7 2.0 59.5
Bangladesh 1,952,412 29,126 128,642,674 166,303,494 1,265.0 3,524.0 1.2 1.5 77.4
Japan 7,436,434 29,104 102,978,850 126,050,796 347.8 39,002.2 5.9 0.4 81.7
Mexico 5,729,270 323,973 85,708,849 130,262,220 66.4 17,336.5 4.4 5.7 65.8
Russia 17,829,009 366,436 80,337,544 145,912,022 8.8 24,766.0 12.2 2.1 55.1
In [63]:
dfworld3 = dfworld2.sort_values('Population',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Population Countries Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[63]:
Overview Of Top 10 Highest Population Countries Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
China 663,393 4,657 1,280,156,000 1,444,216,102 147.7 15,308.7 0.0 0.7 88.6
India 43,047,594 522,006 998,395,198 1,393,409,033 450.4 6,426.7 3.1 1.2 71.7
United States 80,732,932 989,331 256,880,347 332,915,074 35.6 54,225.4 24.3 1.2 77.2
Indonesia 6,041,269 155,937 198,351,438 276,361,788 145.7 11,188.7 2.2 2.6 71.8
Pakistan 1,527,486 30,368 133,965,057 225,199,929 255.6 5,034.7 0.7 2.0 59.5
Brazil 30,275,219 662,396 182,287,352 213,993,441 25.0 14,103.5 14.1 2.2 85.2
Nigeria 255,670 3,143 22,575,395 211,400,704 209.6 5,338.5 0.1 1.2 10.7
Bangladesh 1,952,412 29,126 128,642,674 166,303,494 1,265.0 3,524.0 1.2 1.5 77.4
Russia 17,829,009 366,436 80,337,544 145,912,022 8.8 24,766.0 12.2 2.1 55.1
Mexico 5,729,270 323,973 85,708,849 130,262,220 66.4 17,336.5 4.4 5.7 65.8
In [64]:
fig = make_subplots(rows=2, cols=2, specs=[[{'secondary_y': True}, {'secondary_y': True}],
                                          [{'secondary_y': True}, {'secondary_y': True}]],
                    horizontal_spacing = 0.1, vertical_spacing = 0.3,
                    
subplot_titles=('<b>World Top 10 Covid19 Positive Cases</b>',
                '<b>ASEAN Covid19 Positive Cases</b>',
                '<b>World Top 10 Covid19 Death Cases</b>',
                '<b>ASEAN Covid19 Death Cases</b>'))
#Graph 1
fig.append_trace(go.Bar(x = dfworld_highest['Country'], y = dfworld_highest['Total Cases'],
                        name='Death Cases',marker_color='red'),row=1, col=1)
#Graph 2
fig.append_trace(go.Bar(x = df_asean['Country'], y = df_asean['Total Cases'],
                        name='Death Vax Cases',marker_color='blue'),row=1, col=2)
#Graph 3
fig.append_trace(go.Bar(x = dfworld_highest['Country'], y = dfworld_highest['Total Deaths'],
                        name='Death Cases',marker_color='red'),row=2, col=1)
#Graph 4
fig.append_trace(go.Bar(x = df_asean['Country'], y = df_asean['Total Deaths'],
                        name='Death Vax Cases',marker_color='blue'),row=2, col=2)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=600,showlegend=False)
#fig.update_layout(height=400,showlegend=False,title_text='Yearly and Monthly Total New And Recovered Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()

Notes:

All datasets in this reports were retrieved from:-

1. Malaysia MOH Github Account

2. CITF Github Account

3. COVID-19 Data Repository by the Center for Systems Science and Engineering (CSSE) at Johns Hopkins University Github Account

End Of Report